package web.enumeditor;

import org.codehaus.jackson.map.annotate.JsonSerialize;

/**
 * 性别.
 */
@JsonSerialize(using = SexTypeJsonSerializer.class)
public enum Sex {
    male("男"), female("女");

    private String chineseName;

    private Sex(String chineseName) {
        this.chineseName = chineseName;
    }

    public String getChineseName() {
        return chineseName;
    }

    public static Sex getSexByChineseName(String chineseName) {
        if (null == chineseName || chineseName.trim().equals(""))
            return null;
        Sex result = null;
        for (Sex s : Sex.values()) {
            if (s.getChineseName().equals(chineseName)) {
                result = s;
                break;
            }
        }
        return result;
    }

    public static Sex getSexByOrdinal(int mark) {
        Sex result = null;
        for (Sex s : Sex.values()) {
            if (s.ordinal() == mark) {
                result = s;
                break;
            }
        }
        return result;
    }

    @Override
    public String toString() {
        return getChineseName();
    }

    public static void main(String[] args) {
        System.out.println(Sex.female.name());
    }
}
